<?php


function admin_token_check() {
	global $longip, $time, $useragent, $conf;
	$useragent_md5 = md5($useragent);

	$key = $useragent_md5.$conf['auth_key'];
	$admin_token = param('bbs_finance_token');
	if(empty($admin_token)) {
		$s = false;
	} else {
		$s = xn_decrypt($admin_token, $key);
		if(empty($s)) {
			setcookie('bbs_finance_token', '', 0, '', '', '', TRUE);
			message(-1, lang('admin_token_expiry'));
		}
	}
	return $s;
}

function admin_token_set() {
	global $longip, $time, $useragent, $conf, $admin;
	$useragent_md5 = md5($useragent);
	$key = $useragent_md5.$conf['auth_key'];
	$admin_token = param('bbs_finance_token');
	$s = $admin['uid'];
	$admin_token = xn_encrypt($s, $key);
	setcookie('bbs_finance_token', $admin_token, $time + 36000, '',  '', 0, TRUE);
}

function admin_token_clean() {
	global $time;
	setcookie('bbs_finance_token', '', $time - 86400, '', '', 0, TRUE);
}

function admin_authority_check(){
	global $admin;
	return (!$admin) ? 0 : 1;
}

// bootstrap style
function admin_tab_active($arr, $active) {
	$s = '';
	foreach ($arr as $k=>$v) {
		$s .= '<a role="button" class="btn btn-secondary'.($active == $k ? ' active' : '').'" href="'.$v['url'].'">'.$v['text'].'</a>';
	}
	return $s;
}

?>